package org.sam.swing.table.verification;

import java.awt.Component;

import org.jdesktop.swingx.decorator.ComponentAdapter;
import org.jdesktop.swingx.decorator.HighlightPredicate;
import org.sam.swing.table.JSTable;
import org.sam.swing.table.JSTableModel;

/**
 * 带校验功能的过滤器对象
 * 
 * @author sam
 *
 */
public class VerificationHighlightPredicate implements HighlightPredicate {

	/**
	 * 校验对象
	 */
	private Verification verification;

	/**
	 * 校验对象
	 * 
	 * @return
	 */
	public Verification getVerification() {
		return verification;
	}

	/**
	 * 校验对象
	 * 
	 * @param verification
	 */
	public void setVerification(Verification verification) {
		this.verification = verification;
	}
	
	/**
	 * 带有校验的高亮显示过滤器
	 * @param verification
	 */
	public VerificationHighlightPredicate(Verification verification){
		this.setVerification(verification);
	}

	/**
	 * 是否高亮显示
	 */
	@Override
	public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
		if (adapter.getComponent() instanceof JSTable) {
			if (this.verification != null) {
				JSTable table = (JSTable) adapter.getComponent();
				JSTableModel<?> model = (JSTableModel<?>) table.getModel();

				return !verification.check(model, adapter.row, adapter.column);
			}
		}
		return false;
	}
}
